//
//  StoreHotelInfoView.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/20.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "ZZStarView.h"

#import "StoreHotelInfoView.h"
#import "HorizontalCollectionView.h"

@interface StoreHotelInfoView ()

@property (nonatomic, strong) ZZStarView *starView;

@property (nonatomic, strong) HorizontalCollectionView *promiseCollectionView;
@end

@implementation StoreHotelInfoView

+ (CGFloat)calculateHeightWithModel:(StoreHotelDetailModel *)model {
    
    CGFloat nameHeight = 80;
    if (model.SellerPromiseLabelAuthernticationList.count == 0) {
        nameHeight = 60;
    }
    
    CGFloat mapHeight  = 60;
    
    CGFloat wyxHeight  = 40;
    if (model.seller.examStatus != 2) {
        wyxHeight = CGFLOAT_MIN;
    }
    
    CGFloat introduceHeight = 70 + [Utilities getStringHeightWithText:model.seller.sellerStory font:[UIFont systemFontOfSize:12] viewWidth:(TTScreenWidth - 40 - 30)];
    return nameHeight + mapHeight + wyxHeight + introduceHeight;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    WEAKSELF
    [self.mapControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (weakSelf.StoreHotelInfoViewBlock) {
            weakSelf.StoreHotelInfoViewBlock(StoreHotelInfoActionType_mapNavi);
        }
    }];
    
    self.wuyouxuanControl.userInteractionEnabled = YES;
    [self.wuyouxuanControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (weakSelf.StoreHotelInfoViewBlock) {
            weakSelf.StoreHotelInfoViewBlock(StoreHotelInfoActionType_wuyouxuan);
        }
    }];
    
    [self.wuyouxyanLabBG addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (weakSelf.StoreHotelInfoViewBlock) {
            weakSelf.StoreHotelInfoViewBlock(StoreHotelInfoActionType_wuyouxuan);
        }
    }];
    
    [self.starBGView addSubview:self.starView];

    [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    [self.promiseBGView addSubview:self.promiseCollectionView];
    [self.promiseCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
}

- (IBAction)imAction:(id)sender {
    if (self.StoreHotelInfoViewBlock) {
        self.StoreHotelInfoViewBlock(StoreHotelInfoActionType_im);
    }
}


- (void)fillHeadWithModel:(StoreHotelDetailModel *)model {
    
    [self.promiseCollectionView fillPromiseData:model.SellerPromiseLabelAuthernticationList];

    self.starView.grade = model.seller.sellerEvaluateStar;
    
    self.hotelNameLab.text = model.seller.sellerName;
    
    self.hotelAddressLab.text = model.seller.sellerAddress;
    
    if (model.seller.lat > 0) {
        
        if (model.seller.distance < 1000) {
            self.hotelAddressLab.text = [NSString stringWithFormat:@"%.fm | %@",model.seller.distance,model.seller.sellerAddress];
        } else {
            self.hotelAddressLab.text = [NSString stringWithFormat:@"%.fkm | %@",model.seller.distance/1000,model.seller.sellerAddress];
        }
    } else {
        self.hotelAddressLab.text = model.seller.sellerAddress;
    }
    
    self.hotelIntroduceLab.text = model.seller.sellerStory;
            
    if (model.seller.minPrice == model.seller.maxPrice) {
        self.hotelPriceLab.text = [NSString stringWithFormat:@"￥%@/桌",[Utilities changeDoubleToString:model.seller.maxPrice]];
        
        if (model.seller.maxPrice == 0 && model.seller.minPrice == 0) {
            self.hotelPriceLab.text = @"";
        }
        
    } else {
        self.hotelPriceLab.text = [NSString stringWithFormat:@"￥%@ ~ ￥%@/桌",[Utilities changeDoubleToString:model.seller.minPrice],[Utilities changeDoubleToString:model.seller.maxPrice]];
        
        if (model.seller.minPrice>0 && model.seller.maxPrice==0) {
            self.hotelPriceLab.text = [NSString stringWithFormat:@"￥%@/桌起",[Utilities changeDoubleToString:model.seller.minPrice]];
        }
        
        if (model.seller.maxPrice>0 && model.seller.minPrice==0) {
            self.hotelPriceLab.text = [NSString stringWithFormat:@"￥%@/桌封顶",[Utilities changeDoubleToString:model.seller.minPrice]];
        }
    }

    
    self.wuyouxuanControl.hidden = YES;
    self.wyxIcon1.hidden = YES;
    self.wyxLab1.hidden = YES;
    self.wyxIcon2.hidden = YES;
    self.wyxLab2.hidden = YES;
    self.wyxIcon3.hidden = YES;
    self.wyxLab3.hidden = YES;
    self.wyxIcon4.hidden = YES;
    self.wyxLab4.hidden = YES;
    
    if (model.seller.examStatus == 2) {
        
        self.wuyouxuanControl.hidden = NO;
        self.wyxHeight.constant = 40;
        for (int i = 0; i < model.sysWorryFreeLabel.count; i++) {
            
            if (i == 0) {
                self.wyxIcon1.hidden = NO;
                self.wyxLab1.hidden = NO;
                self.wyxLab1.text = model.sysWorryFreeLabel[i].labelName;
            }else if (i == 1) {
                self.wyxIcon2.hidden = NO;
                self.wyxLab2.hidden = NO;
                self.wyxLab2.text = model.sysWorryFreeLabel[i].labelName;
            }else if (i == 2) {
                self.wyxIcon3.hidden = NO;
                self.wyxLab3.hidden = NO;
                self.wyxLab3.text = model.sysWorryFreeLabel[i].labelName;
            }else if (i == 3) {
                self.wyxIcon4.hidden = NO;
                self.wyxLab4.hidden = NO;
                self.wyxLab4.text = model.sysWorryFreeLabel[i].labelName;
            }
        }
    } else {
        self.wyxHeight.constant = CGFLOAT_MIN;
    }
    
    if (model.SellerPromiseLabelAuthernticationList.count > 0) {
        self.infoHeight.constant = 80;
    } else {
        self.infoHeight.constant = 60;
    }
}

- (ZZStarView *)starView {
    
    if (!_starView) {

        _starView = [[ZZStarView alloc] initWithImage:[UIImage imageNamed:@"daxing_nor"] selectImage:[UIImage imageNamed:@"daxing_sel"] starWidth:12 starHeight:12 starMargin:2 starCount:5 callBack:^(CGFloat userGrade, CGFloat finalGrade) {
        }];
        //默认值, 可以不写, 用户可选分值范围是0.5的倍数.(建议在设置分值之前确定此值)
        _starView.sublevel = 0.5;
        //设置分值, 可以不写, 默认显示0分.(self.params是UIViewController在ZZRouter中扩展的属性, 包含了所有参数)
        _starView.grade = 0.0;
        //最小值, 默认0.5可以不写, 用户可以设置的最低分值.
        _starView.miniGrade = 0;
        _starView.frame = CGRectMake(0, 0, 70, 14);

    }
    return _starView;
}

- (HorizontalCollectionView *)promiseCollectionView {
    if (!_promiseCollectionView) {
        _promiseCollectionView = [[HorizontalCollectionView alloc] initWithType:HorizontalCollectionType_hotelDetail];
    }
    return _promiseCollectionView;
}
@end
